package com.example.demo.service.impl;

import com.example.demo.context.BaseContext;
import com.example.demo.mapper.UserDetailMapper;
import com.example.demo.mapper.UserMapper;
import com.example.demo.pojo.entity.User;
import com.example.demo.pojo.entity.UserDetail;
import com.example.demo.pojo.vo.UserDetailVO;
import com.example.demo.service.UserDetailService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserDetailServiceImpl implements UserDetailService {
    @Autowired
    private UserDetailMapper userDetailMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public UserDetailVO getDetail() {
        UserDetailVO userDetailVO = new UserDetailVO();
        UserDetail userDetail=userDetailMapper.getByUserId(BaseContext.getCurrentId());
        BeanUtils.copyProperties(userDetail,userDetailVO);

        User user=userMapper.getById(BaseContext.getCurrentId());
        userDetailVO.setHeight(user.getHeight());
        userDetailVO.setCurrentWeight(user.getCurrentWeight());
        userDetailVO.setTargetWeight(user.getTargetWeight());

        return userDetailVO;
    }
}
